
package flashomatic;

import java.io.*;
import java.util.*;
import javax.microedition.io.*;

public class MMParser {
  private String datei = null;
  
  MMParser(String s){
    datei = s;
    System.out.println("Opening Language Resource: "+datei);
  }
  
  public Vector readTxt() {

    Vector lines = new Vector();
    
    try {
      InputStream in = this.getClass().getResourceAsStream(datei);
      InputStreamReader isr = new InputStreamReader(in, "UTF-8");
      
      StringBuffer buffer = new StringBuffer();
      int ch;
      
      while ((ch = isr.read()) != -1) {
          buffer.append((char)ch);
      }
      
      lines = splitText(buffer.toString());
      
      in.close();
    } catch(Exception e){}
    
    return lines;
    
  }
  
  private Vector splitText(String s){
    Vector v= new Vector();
    String x=new String();
    
    for(int i=0; i<s.length();i++){
      if(s.charAt(i)=='#'){ //indicates comment from # to end of line
        while(s.charAt(i)!='\n'){
          i++;
        }
      }
      
      if (s.charAt(i)=='\n'){
        v.addElement(x.trim());
        x = new String();
      } else
        x+=s.charAt(i);
    }
    
    return v;
  }
}